package com.example.businessserver.service;


import com.example.businessserver.dao.BusinessDao;
import com.example.businessserver.entities.Business;
import com.example.server_engineer.controller.utils.R;
import com.example.server_engineer.service.AbstractTypedService;
import jakarta.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author Administrator
 */

@Service
public class BusinessService
        extends AbstractTypedService<Business,Integer> {
    BusinessDao businessDao;

    BusinessService(BusinessDao dao){
        this.dataContext = dao;
        this.businessDao = dao;
    }
//    @Resource
//    FileStorageService fileStorageService;

    public List<Business> queryAll(){
        List<Business> lst = null;
        try{
            lst = ((BusinessDao) this.dataContext).findAll();
//            log.info("query business: " + lst.size());
            System.out.println("query business: " + lst.size());
        }catch (Exception e){
            System.out.println(e.toString());
//            log.warn(e.toString());
        }
        return lst;
    }
    @Resource
    FoodFeignService foodFeignService;

//    // 根据商家信息查看食物
    public R queryFoodByBusinessName(String businessName) {
        Optional<Business> business = businessDao.findBusinessByName(businessName);

        Integer businessId = null;
        if (business.isPresent()) {
            businessId = business.get().getId();
        }

//        List<Food> food = foodDao.findFoodByBusinessId(businessId);
        return foodFeignService.queryByBusinessId(businessId);
    }

    // 根据商家名称查看商家详细信息
    public Optional<Business>queryByBusinessName(String name){
        return businessDao.findBusinessByName(name);
    }


    public Page<Business> queryCartByPage(Pageable pageable) {
        return businessDao.queryPage(pageable,null);
    }
}
